let app = getApp()

// 工具栏
import utils from '../../utils/util.js';

// 阳历日期转为农历日期
var date2Lunar = require('../../utils/date2Lunar.js');

Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    calendarData: {
      year: new Date().getFullYear(),
      year_h: new Date().getFullYear().toString().slice(0,2),
      year_f: new Date().getFullYear().toString().slice(2,4),
      month: ('0' + (new Date().getMonth() + 1)).slice(-2),
      dataSource: [new Date().getFullYear() + '-' + ('0' + (new Date().getMonth() + 1)).slice(-2) + '-' + ('0' + (new Date().getDate())).slice(-2)],
      showSigned: false,
      showTodaySigned: false,
    },
    lunarData: {
      today: ('0' + (new Date().getDate())).slice(-2),
      lunarMonth: '',
      lunarDay: '',
      lunarYear: '',
    },
    calenderHeight: '340rpx' // 用于监控日历高度
  },

  // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
  attached: function () {
    /**
     * 初始化农历模块数据
     */
    this.initDate()
  },

  /**
   * 组件的方法列表
   */
  methods: {
    initDate() {
      let date = new Date()
      let solarDate = ('0' + (date.getMonth() + 1)).slice(-2) + '月' + ('0' + (date.getDate())).slice(-2) + "日"
      let lunarObj = date2Lunar.sloarToLunar(date.getFullYear(), date.getMonth() + 1, date.getDate())
      let lunarDate = lunarObj.lunarMonth + lunarObj.lunarDay

      let lunarData = {}
      lunarData.today = ('0' + (date.getDate())).slice(-2)
      lunarData.lunarYear = lunarObj.lunarYear
      lunarData.lunarMonth = lunarObj.lunarMonth
      lunarData.lunarDay = lunarObj.lunarDay
      lunarData.td_month = lunarObj.lunarYear
      lunarData.td_day = lunarObj.lunarYear
      this.setData({
        lunarData
      })

      this.checkCalendarHeight()
    },
    checkCalendarHeight() {
      let date = this.data.calendarData.year + '-' + this.data.calendarData.month + '-01'
      let week = new Date(date).getDay()
      let calenderHeight = ''
      if(week > 4) {
        calenderHeight = '398rpx'
      } else if(week <= 4) {
        calenderHeight = '340rpx'
      }
      this.setData({
        calenderHeight: calenderHeight
      })
    },
  }
})
